/*
 * @Date: 2022-02-25 16:57:57
 * @LastEditors: zhaoxm
 * @LastEditTime: 2022-09-15 20:08:26
 * @Description: API公共方法暴露
 */

import { VAxios } from "./src/Axios"
import config from "./src/config"

function createVAxios (opt) {
  return new VAxios(Object.assign(config, opt || {}))
}

// 创建请求实例
export const request = createVAxios()

// GET 请求
export const get = (...parameters) => request.get(...parameters)

// POST请求
export const post = (...parameters) => request.post(...parameters)

export const postField = (api, parameters) => {
  const formData = new FormData()
  formData.append("file", parameters.file)
  return request.post(api, formData)
}

// 下载方法
export const getDownLoadFile = (api, parameters, requestConfig) => {
  return get(api, parameters, {
    responseType: "blob",
    ...requestConfig,
  })
}

export const postDownLoadFile = (api, parameters, requestConfig) => {
  return post(api, parameters, {
    responseType: "blob",
    ...requestConfig,
  })
}
